﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using AccountManagement.DataAccess;

namespace AccountManagement
{
    public class ValueToBrushConverter : IValueConverter  
    {
        protected static SolidColorBrush RedBrush;
        protected static SolidColorBrush GreenBrush;

        static ValueToBrushConverter()
        {
            RedBrush = new SolidColorBrush(Colors.Red);
            GreenBrush = new SolidColorBrush(Colors.Green);
            RedBrush.Freeze();
            GreenBrush.Freeze();
        }

        #region IValueConverter members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var objPhieuThuChi = value as tblPhieuThuChi;
            if (objPhieuThuChi != null && targetType == typeof(Brush) && parameter is string)
            {
                var bCheck = objPhieuThuChi.IsIncoming;
                return bCheck ? GreenBrush : RedBrush;
            }
            return null; 
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        #endregion
    }
}
